/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */
#include <aos/cli.h>
#include "app_bt.h"
#include "smart_audio.h"
#include "combo_net.h"
#include "app_main.h"

static void cmd_app_func(char *wbuf, int wbuf_len, int argc, char **argv)
{
    if (argc == 2) {
        if (strcmp("start", argv[1]) == 0) {
            bt_init();
            bt_open();
        } else if (strcmp("stop", argv[1]) == 0) {
            bt_close();
        }
    } else if (argc > 2) {
        if (strcmp("set_name", argv[1]) == 0) {
            char bt_name[100];
            strcpy(bt_name,argv[2]);
            for(int i=3; i<argc; i++){
                strcat(bt_name," ");
                strcat(bt_name,argv[i]);
            }
            printf("set bt_name:%s\n",bt_name);
            app_bt_gap_set_device_name(bt_name);
        } else if (strcmp("play", argv[1]) == 0) {
            if (strcmp("start", argv[2]) == 0) {
                app_bt_avrcp_send_passthrouth_cmd(APP_BT_AVRCP_CMD_PLAY);
            } else if (strcmp("stop", argv[2]) == 0) {
                app_bt_avrcp_send_passthrouth_cmd(APP_BT_AVRCP_CMD_STOP);
            } else if (strcmp("pause", argv[2]) == 0) {
                app_bt_avrcp_send_passthrouth_cmd(APP_BT_AVRCP_CMD_PAUSE);
            } else if (strcmp("next", argv[2]) == 0) {
                app_bt_avrcp_send_passthrouth_cmd(APP_BT_AVRCP_CMD_FORWARD);
            } else if (strcmp("prev", argv[2]) == 0) {
                app_bt_avrcp_send_passthrouth_cmd(APP_BT_AVRCP_CMD_BACKWARD);
            }
        } else if (strcmp("vol", argv[1]) == 0) {
            app_bt_avrcp_change_vol(atoi(argv[2]));
            smtaudio_vol_set(atoi(argv[2]));
        }
    }
}

void cli_reg_cmd_bt(void)
{
    static const struct cli_command cmd_info_bt = {"a2dp", "a2dp test", cmd_app_func};
    aos_cli_register_command(&cmd_info_bt);
}
/* 
    蓝牙播歌使用步骤
    开启a2dp：
        a2dp start
    设置设备名称, 如果不设置 默认 name 为：5654-0001：
        a2dp set_name YoC
    等待手机连接设备

    手机连上后，可以通过命令控制
    下一首
        a2dp play next
    上一首
        a2dp play prev
    停止播放
        a2dp play stop
    开始播放
        a2dp play start
    设置音量
        a2dp vol [0 - 100]
    关闭a2dp
        a2dp stop



    蓝牙配网使用步骤：

    1.设备烧入五元组
    2.ble_prov 2
        设备自动重启
    3.使用云智能app进行配网
*/